<?php

class NRHC_Template {
	var $_tpl = null;
	var $_document = null;
	var $_app = null;
	var $template = '';

	function NRHC_Template ($template) {
		$this->_tpl = $template;
    $this->_document = &JFactory::getDocument();
		$this->_app = &JFactory::getApplication();
		$this->template = $template->template;
	}

	function baseurl(){
		return JURI::base();
	}

	function templateurl(){
		return JURI::base()."templates/".$this->template;
	}
	
	function isFrontPage(){
		return (JRequest::getCmd( 'view' ) == 'frontpage') ;
	}

	function sitename() {
		/* this is how it was done in J!1.5
		 * and may still work since Joomla documentation is lacking
		$config = new JConfig();
		return $config->sitename;
		*/
		return $this->_app->getCfg('sitename');
	}
	
	function getParam($name=NULL)
	{
		return $this->_tpl->params->get( $name );
	}

	function getWithContent()
	{
		// return with-left and with-right
		if( $this->_tpl->countModules('left') && $this->_tpl->countModules('right') ) return "with-left-and-right";
		if( $this->_tpl->countModules('left') ) return "with-left";
		if( $this->_tpl->countModules('right') ) return "with-right";
    return "full";
	}
	
	/**
	 * browser()
	 * Returns an abbreviation of MSIE browser versions
	 */
	function browser() {
		$agent = $_SERVER['HTTP_USER_AGENT'];
		if ( strpos($agent, 'MSIE') && !preg_match('/opera/i',$agent) )
		{
			$pattern = "#msie (\d)\.\d#i";
			preg_match($pattern, $agent, $matches);
			$browser = "IE IE" . $matches[1];
		}
		return $browser;
	}

  /**
   * addStyleSheet
   * use the Joomla addStyleSheet function to que a stylesheet for load
   *
   * @string $file the file name
   * @bool   $override if true, then use $file as the complete path otherwise default to template path
   */
  public function addStyleSheet( $file=NULL, $override=false )
  {
    $path = $override ? $file : $this->templateurl() . '/css/' . $file;
    $this->_document->addStyleSheet( $path, "text/css", "all" );
  }

  /**
   * addScript
   * use the Joomla addScript function to que a script for load
   *
   * @string $file the file name
   * @bool   $override if true, then use $file as the complete path otherwise default to template path
   */
  public function addScript( $file=NULL, $override=false )
  {
    $path = $override ? $file : $this->templateurl() . '/js/' . $file;
    $this->_document->addScript( $path );
  }

}
?>
